# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

project(plugin_ecmascript_compiler)

add_subdirectory(ecmascript_extensions)

set(GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${GENERATED_DIR})

panda_isa_gen(
        TEMPLATES
            "ecmascript_inst_builder_gen.cpp.erb"
        SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/templates
        API ${PANDA_ROOT}/assembler/asm_isapi.rb
        DESTINATION ${GENERATED_DIR}
        )

add_dependencies(arkcompiler isa_gen_${PROJECT_NAME})
add_dependencies(arkcompiler runtime_options_gen)

set(COMPILER_SOURCES
  ${CMAKE_CURRENT_SOURCE_DIR}/optimizer/code_generator/compiler_base_types.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/optimizer/optimizations/ecma_inlining.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/inline_intrinsics_ecmascript.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/codegen_intrinsics_ecmascript.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/optimizer/ir_builder/ecmascript_inst_builder.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/optimizer/ecma_pipeline.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/optimizer/optimizations/inline_call_intrinsics.cpp
)

panda_target_sources(arkcompiler PRIVATE ${COMPILER_SOURCES})

panda_target_include_directories(arkcompiler PUBLIC
  ${GENERATED_DIR}
)

add_inst_templates(${CMAKE_CURRENT_SOURCE_DIR}/optimizer/ir_builder/ecmascript_inst_templates.yaml)

add_merge_plugin(PLUGIN_NAME "create_pipeline.inl" INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/plugin_files/ecma_create_pipeline.inl")

add_compiler_options(${CMAKE_CURRENT_SOURCE_DIR}/ecma_compiler.yaml)
